<?
$page = "banners";
if ($_GET['id']) {
    $data = BannersControl::Select((int) $_GET['id']);
}
if($data[0]['expiration']){
    $data = date("d/m/Y",  strtotime($data[0]['expiration']));
}
?>
<script>
    $(function() {
        $("#expiration").datepicker({
             dateFormat: "dd/mm/yy"
        });
    });
</script>
<div class="container-form">
    <h1>Banners</h1>
    <form action="<?= __ADMIN_URI__; ?>actions/<?= $page ?>.php" method="post" enctype="multipart/form-data" id="form-cadastre" onsubmit="return Validation();">
        <input type="hidden" name="redirect" id="redirect" value="<?= __ADMIN_URI__ . $page ?>">
        <input type="hidden" name="id" id="codigo" value="<?= $data[0]['id']; ?>">
        <div class="input">
            Título:
            <input type="text" name="title" id="title" class="required" size="40" value="<?= $data[0]['title'] ?>">
            Tipo:
            <select name="type" id="type" class="required">
                <option value=""> -- Local -- </option>
                <option value="1" <? if ($data[0]['type'] == 1) { ?> selected="selected" <? } ?>>(752x92 ) Topo</option>
                <option value="2" <? if ($data[0]['type'] == 2) { ?> selected="selected" <? } ?>>(370x264) Tv</option>
                <option value="3" <? if ($data[0]['type'] == 3) { ?> selected="selected" <? } ?>>(300x100) Meio</option>
                <option value="4" <? if ($data[0]['type'] == 4) { ?> selected="selected" <? } ?>>(180x50 ) Lateral</option>
                <option value="5" <? if ($data[0]['type'] == 5) { ?> selected="selected" <? } ?>>(627x100) Busca</option>
                <option value="6" <? if ($data[0]['type'] == 6) { ?> selected="selected" <? } ?>>(120x60 ) Lateral Busca</option>
                <option value="7" <? if ($data[0]['type'] == 7) { ?> selected="selected" <? } ?>>(220x122) Top Leteral</option>
            </select>
        </div>
        <div class="input">
            Arquivo: <input type="file" name="filepicture" id="filepicture" class="required">
            Data Vencimento: <input type="text" id="expiration" name="expiration" size="6" class="required" value="<?=$data;?>">
        </div>
        <div class="input">
            Tipo de direcionamento:<br>
            <input type="radio" name="direcionamento" id="direcionamento_0" value="1" onclick="BannerType(1)">Empresa
            <input type="radio" name="direcionamento" id="direcionamento_1" value="2" onclick="BannerType(2)">Link
            <div class="input empresa">
                Empresa:
                <select name="id_enterprise">
                    <option value=""> -- Empresa -- </option>
                    <?
                    $data_empresa = EmpresasControl::Listar();
                    if (isset($data_empresa)) {
                        foreach ($data_empresa as $list_enterprise) {
                            ?>
                            <option value="<?= $list_enterprise['id'] ?>"><?= $list_enterprise['corporatename'] ?></option>
                            <?
                        }
                    }
                    ?>
                </select>
            </div>
            <div class="input link">
                Link: 
                <input type="text" name="href" id="href">
                Janela:
                <select name="target" id="target">
                    <option value=""> -- Janela -- </option>
                    <option value="_blank">Nova Janela/Aba</option>
                    <option value="_self">Mesma Janela</option>
                </select>
            </div>
        </div>

        <div class="input">
            <input type="submit" value="Salvar">
            <input type="button" value="Novo" onclick="location.href = $('#redirect').val();">
        </div>
        
    </form>
    <hr>
    <div class="list">
        <div class="list-data">
            <ul>
                <li>Cód</li>
                <li>Título</li>
                <li>Vencimento</li>
                <li>Opções</li>
            </ul>
            <?php
            $data_banner = BannersControl::Select();
            if (isset($data_banner)) {
                foreach ($data_banner as $list) {
                    $urldelete = __ADMIN_URI__ . "actions/" . $page . ".php?id=" . $list['id'] . "&redirect=" . __ADMIN_URI__ . $page;
                    ?>
                    <ul>
                        <li><?= $list['id']; ?></li>
                        <li><?= $list['title']; ?></li>
                        <li><?= date("d/m/Y",  strtotime($list['expiration'])); ?></li>
                        <li><a href="javascript:ApagarRegistro('<?= $urldelete ?>')">Excluir</a></li>
                    </ul>
                    <?
                }
            } else {
                ?>
                <ul>
                    <li>Nenhum banner adicionado!</li>
                </ul>
                <?
            }
            ?>

        </div>
    </div>
</div>

